package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.tanhua.dubbo.mapper.QuestionMapper;
import com.tanhua.model.db.Question;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class QuestionApiImpl implements QuestionApi {
    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public Question selectQuestion(Long userId) {
        LambdaQueryWrapper<Question> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Question::getUserId, userId);
        Question question = questionMapper.selectOne(wrapper);
        return question;
    }

    @Override
    public void saveQuestion(Question question) {

         //前端查询的时候
        questionMapper.insert(question);
    }

    @Override
    public void update(Question question) {
        //如果用户问题表原本已存在，根据用户查询回来就会有id，在这直接更新就行
        questionMapper.updateById(question);
    }

    @Override
    public Question fingByUser(Long userId) {
        LambdaQueryWrapper<Question> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Question::getUserId,userId);
        Question question = questionMapper.selectOne(wrapper);
        return question;
    }
}
